<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width:100%">
    <el-col>
      <span v-if="data.company"><strong>{{ data.name }}</strong></span>
      <span v-else>{{ data.name }}</span>
    </el-col>
    <el-col :span="5">
      <el-row type="flex">
        <el-col>{{ data.manager }}</el-col>
        <el-col>
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addcompany">添加部门</el-dropdown-item>
              <el-dropdown-item v-if="!data.company" @click.native="editcompany">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!data.company" @click.native="delcompany(data.id)">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delCompanyLists } from '@/api/departments'
export default {
  props: {
    data: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
    }
  },
  methods: {
    async delcompany(id) {
      await this.$confirm('此操作将永久删除该部门?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error' })
      await delCompanyLists(id)
      this.$emit('delcompany')
    },
    addcompany() {
      this.$emit('addcompany', this.data.id || '')
    },
    editcompany() {
      this.$emit('editcompany', this.data.id || '')
    }
  }
}
</script>

<style>

</style>
